package com.book.domain;

public class SplitPage {

	
	@Override
	public String toString() {
		return "SplitPage [totalrecord=" + totalrecord + ", perpagerecord="
				+ perpagerecord + ", totalpage=" + totalpage + ", currentpage="
				+ currentpage + ", startpage=" + startpage + ", stoppage="
				+ stoppage + ", endpage=" + endpage + ", startrecord="
				+ startrecord + ", stoprecord=" + stoprecord + "]";
	}
	int perpagerecord;//每页显示记录数
	int totalpage;//总页面数
	int currentpage;//当前页面数
	int startpage;//开始页面数
	int stoppage;//结束页面数
	int endpage;//最后一页
	int startrecord;//起始记录数
	int stoprecord;//结束记录数
	int totalrecord;//总记录数
	public int getStartrecord() {
		return startrecord;
	}
	public void setStartrecord(int startrecord) {
		this.startrecord = startrecord;
	}
	public int getStoprecord() {
		return stoprecord;
	}
	public void setStoprecord(int stoprecord) {
		this.stoprecord = stoprecord;
	}
	public int getTotalrecord() {
		return totalrecord;
	}
	public void setTotalrecord(int totalrecord) {
		this.totalrecord = totalrecord;
	}
	public int getPerpagerecord() {
		return perpagerecord;
	}
	public void setPerpagerecord(int perpagerecord) {
		this.perpagerecord = perpagerecord;
	}
	public int getTotalpage() {
		return totalpage;
	}
	public void setTotalpage(int totalpage) {
		this.totalpage = totalpage;
	}
	public int getCurrentpage() {
		return currentpage;
	}
	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}
	public int getStartpage() {
		return startpage;
	}
	public void setStartpage(int startpage) {
		this.startpage = startpage;
	}
	public int getStoppage() {
		return stoppage;
	}
	public void setStoppage(int stoppage) {
		this.stoppage = stoppage;
	}
	public int getEndpage() {
		return endpage;
	}
	public void setEndpage(int endpage) {
		this.endpage = endpage;
	}
   
	public SplitPage(int totalrecord, int perpagerecord, int totalpage,
			int currentpage, int startpage, int stoppage, int endpage,
			int startrecord, int stoprecord) {
		super();
		this.totalrecord = totalrecord;
		this.perpagerecord = perpagerecord;
		this.totalpage = totalpage;
		this.currentpage = currentpage;
		this.startpage = startpage;
		this.stoppage = stoppage;
		this.endpage = endpage;
		this.startrecord = startrecord;
		this.stoprecord = stoprecord;
	}
	
	public SplitPage(){
		
	}
	public static SplitPage calculatepage(SplitPage splitPage){
		
	    int m_totalrecord=	splitPage.getTotalrecord();
	    int m_perpagerecord=splitPage.getPerpagerecord();
	    int m_currentpage= splitPage.getCurrentpage();
	    int m_totalpage=0;
	    int m_startpage=0;
	    int m_stoppage=0;
	    int m_startrecord=0;
	    int m_stoprecord=0;
	    if(m_totalrecord%m_perpagerecord==0){
	    	m_totalpage=m_totalrecord/m_perpagerecord;
	    }else {
	    	m_totalpage=m_totalrecord/m_perpagerecord+1;
		}
	    if(m_currentpage-2>0){
	    	m_startpage=m_currentpage-2;
	    }else {
	    	m_startpage=1;
		}
	    if(m_currentpage+2>13){
	    	m_stoppage=13;
	    }else {
			m_stoppage=m_currentpage+2;
		}
	    m_startrecord=(m_currentpage-1)*m_perpagerecord+1;
	    if(m_currentpage*m_perpagerecord<=m_totalrecord){
	    	m_stoprecord=m_currentpage*m_perpagerecord;
	    }else {
			m_stoprecord=m_totalrecord;
		}
	    SplitPage newsplitpage=new SplitPage(m_totalrecord, m_perpagerecord, m_totalpage, m_currentpage, m_startpage, m_stoppage, m_totalpage, m_startrecord, m_stoprecord);
		System.out.println(newsplitpage);
	    return newsplitpage;
	}
}
